#!/usr/bin/env python3
# _._ coding:utf-8 _._


import os
import sys
import time
import service

path = os.path.split(os.path.realpath(__file__))[0]
sys.path.append(path)
data_path = os.path.join(path, 'data')
timestamp = 0

if __name__ == '__main__':
    if sys.argv[1] == 'start':
        service.Service().start()
    else:
        with open(os.path.join(data_path, '.command'), 'w') as f:
            f.write(str.strip(sys.argv[1], " "))

    while True:
        if timestamp >= 30:
            print("timeout")
            break
        with open(os.path.join(data_path, '.status')) as f:
            status = f.readline()
            if status == '1':
                print("success")
                break
            elif status == '-1':
                print("fail")
                break

        time.sleep(1)
        timestamp += 1
